# -*- coding: utf-8 -*-
from django import forms

from google.appengine.ext.db import djangoforms
from google.appengine.ext import db

from mobile.models import TextMe
from mobile.decorators import render_to

from gcalendar import CalendarEventMsg, send_cem_by_sms
import logging

class TextMeForm(djangoforms.ModelForm):
    class Meta:
        model = TextMe
        exclude = ('id', 'date',)

@render_to('mobile/textme/textme.html')
def textme(request):
    form = TextMeForm()
    if request.method == 'POST':
        form = TextMeForm(request.POST)
        if form.is_valid():
            textme = form.save(commit=False)
            textme.put()
            cem = CalendarEventMsg(title=textme.text, content='from mobile web')
            send_cem_by_sms(cem)
            return {'success': 'Sent message. It takes some time to check.'}
    return {'form': form}